//
//  PYStudyRNController.m
//  IHome
//
//  Created by 朱吉峥 on 2020/2/1.
//  Copyright © 2020 com.zhujizheng. All rights reserved.
//

#import "PYStudyRNController.h"
#import "UITableViewCell+PYAdd.h"
#import "PYStudyRNDetailController.h"
#import "PYRNUpdate.h"

@interface PYStudyRNController () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tbView;

@property (nonatomic, strong) NSArray *moduleArray;

@end

@implementation PYStudyRNController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"StudyRN";
    self.moduleArray = @[@"Study",
                         @"ShowTextAndLog",
                         @"MyDate",
                         @"FlatListDemo",
                         @"TestTableView",
                         @"HelloWorld",
                         @"SampleAppMovies",
                         @"Props",
                         @"State",
                         @"Style",
                         @"FixedWidthHeight",
                         @"FlexWidthHeight",
                         @"Flexbox",
                         @"JustifyContent",
                         @"AlignItems",
                         @"TextInputTest",
                         @"ButtonTest",
                         @"TouchableTest",
                         @"ScrollViewTest",
                         @"FlatListTest",
                         @"SectionListTest",
                         @"FetchTest",
                         @"RoleInfoView",
                         @"TestRNMethodTool",
                         @"TestAlertName",
                         @"MultiTypeDemo",
                         @"CommunityGuidesView",
                         @"AnimateTest"];
    [self initTbView];
}

#pragma mark - tbView
- (UITableView *)tbView
{
    if (!_tbView) {
        _tbView = [UITableView new];
        _tbView.delegate = self;
        _tbView.dataSource = self;
        [_tbView makeDefaultStyle];
    }
    return _tbView;
}

- (void)initTbView
{
    [self.view addSubview:self.tbView];
    [self.tbView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(0);
    }];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.moduleArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    PYLabelCell *cell = [PYLabelCell cellWithTableView:tableView];
    cell.textLabel.text = [self.moduleArray objectAtSafeIndex:indexPath.row];
    [cell setLightSelectedBackgroundColor];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 55;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return [UIView new];
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    return [UIView new];
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 10;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 10;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    NSString *moduleName = [self.moduleArray objectAtSafeIndex:indexPath.row];
    PYStudyRNDetailController *controller = [PYStudyRNDetailController createWithModule:moduleName];
    [self.navigationController pushViewController:controller animated:YES];
}

@end
